<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Examples;
use App\Http\Controllers\Controller;
use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;

class HomeController extends Controller
{

    //获取是否拥有接待部权限
    protected function reception(): bool
    {
        return Admin::user()->isAdministrator() || Admin::user()->can('reception-customer');
    }
    //获取是否拥有销售权限
    protected function sale(): bool
    {
        return Admin::user()->isAdministrator() || Admin::user()->can('sale-customer');
    }

    //获取是否拥有复诊权限
    protected function returnVisit(): bool
    {
        return Admin::user()->isAdministrator() || Admin::user()->can('return-customer');
    }

    public function index(Content $content): Content
    {
        return $content
            ->header('Dashboard')
            ->body(function (Row $row) {
                $row->column(6, function (Column $column) {
                    if ($this->sale()) {
                        $column->row(new Examples\Sale());//销售成交量
                    }
                    if ($this->returnVisit()) {
                        $column->row(new Examples\Merchant());//招商成交量
                    }
                    if ($this->reception()) {
                        $column->row(new Examples\Customer());//客户录入量
                    }
                });

                $row->column(6, function (Column $column) {
                    if ($this->sale()) {
                        $column->row(new Examples\SalePerformance());//销售成交额
                    }
                    if ($this->returnVisit()) {
                        $column->row(new Examples\MerchantPerformance());//招商成交额
                    }
                });
            });
    }
}
